#include "substationinfowindow.h"
#include "ui_substationinfowindow.h"

/*
 * Date:        2022/11/17
 * Name:        王宇轩
 * Student ID:  20301142
 * Description: 这个类是列车信息查询是的子窗口，
 *              显示一整条线路的经停站信息
*/

SubStationInfoWindow::SubStationInfoWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SubStationInfoWindow)
{
    ui->setupUi(this);
    this->setFixedSize(this->geometry().size());
}

SubStationInfoWindow::~SubStationInfoWindow()
{
    delete ui;
}

//获取经停站的信息，并展示在当前界面
void SubStationInfoWindow::receiveSubInfo(QSqlQuery result)
{
    //清空上一次查询到的内容
    int rowNum=ui->trainNumInfoTable->rowCount();
    for(int i=0;i<rowNum;i++){
        ui->trainNumInfoTable->removeRow(0);
    }

    int columns=ui->trainNumInfoTable->columnCount();

    for(int i=0;result.next();i++){
        //增加一行
        ui->trainNumInfoTable->insertRow(i);
        //填充每一列的数值
        for(int j=0;j<columns;j++){
            ui->trainNumInfoTable->setItem(i,j,new QTableWidgetItem(result.value(j).toString()));
        }
    }
}
